package com.max.sportmanage.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.max.sportmanage.common.Result;
import com.max.sportmanage.entity.SysPermission;
import com.max.sportmanage.mapper.SysPermissionMapper;
import com.max.sportmanage.service.SysPermissionService;
import com.max.sportmanage.util.PageResult;
import com.max.sportmanage.util.QueryInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: java-sport-manage
 * @description:
 * @author: max-qaq
 * @create: 2021-11-15 22:17
 **/
@Service
@Slf4j
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    SysPermissionMapper sysPermissionMapper;

    @Override
    public Result findPage(QueryInfo queryInfo) {
        log.info("开始权限数据分页:页码--->{},每页大小---->{},---->{}查询内容",queryInfo.getPageNumber(),queryInfo.getPageSize(),queryInfo.getQueryString());
        PageHelper.startPage(queryInfo.getPageNumber(),queryInfo.getPageSize());
        Page<SysPermission> page = sysPermissionMapper.findPage(queryInfo.getQueryString());
        long total = page.getTotal();
        List<SysPermission> result = page.getResult();
        log.info("查询结果--->{}",result);
        log.info("查询总条数---->{}",total);
        log.info("分页列表--->{}",result);

        return new PageResult<>(total,result);
    }

    @Override
    public Result insert(SysPermission sysPermission) {
        sysPermissionMapper.insert(sysPermission);
        return Result.SUCCESS("添加权限数据成功");
    }

    @Override
    public Result delete(Long id) {
        sysPermissionMapper.delete(id);
        return Result.SUCCESS("删除权限成功");
    }

    @Override
    public Result update(SysPermission sysPermission) {
        sysPermissionMapper.update(sysPermission);
        return Result.SUCCESS("修改权限成功");
    }
}
